<%--
  Created by IntelliJ IDEA.
  User: 86135
  Date: 2023/3/26
  Time: 15:31
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改信息</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入 Bootstrap -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/css/semantic.min.css">
    <script src="${pageContext.request.contextPath}/statics/js/semantic.min.js"></script>
    <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
    <style>
        body{
            background-image: url("${pageContext.request.contextPath}/statics/images/bg.png");
            font-size: 15px;
        }
    </style>
</head>
<body>
<div class="container">

    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="page-header">
                <h1>
                    <small>修改信息</small>
                </h1>
            </div>
        </div>
    </div>

    <form id="item" enctype="multipart/form-data">
        <input type="hidden" name="bookISBN" value="${book.getBookISBN()}"/>
        <%--显示书籍图片--%>
        <img src="${pageContext.request.contextPath}/book/readPhoto?bookISBN=${book.getBookISBN()}" width="400px" height="400px" style="float: left;margin-left: 10%">
        <div >
            <div style="float: left;margin-left: 12%;">书籍名称：<input type="text" name="bookName" value="${book.getBookName()}" style="border-radius: 5px;"/></div>
            <br><br><br>
            <div style="float: left;margin-left: 12%;">书籍数量：<input type="number" name="bookCounts" value="${book.getBookCounts()}" style="border-radius: 5px;margin-right: 30px;"/></div>
            <br><br><br>
            <div style="float: left;margin-left: 12%;">书籍价格：<input type="text" name="bookPrices" value="${book.getBookPrices()}" style="border-radius: 5px;margin-right: 30px;"/></div>
            <br><br><br>
            <div style="float: left;margin-left: 12%;">书籍作者：<input type="text" name="author" value="${book.getAuthor()}" style="border-radius: 5px;margin-right: 30px;"/></div>
            <br><br><br>
            <div style="float: left;margin-left: 12%;">书籍详情：<input type="text" name="detail" value="${book.getDetail()}" style="border-radius: 5px;margin-right: 30px;"/></div>
            <br><br><br>
        </div>
        <a href="${pageContext.request.contextPath}/comment/allCommentsWithBookAdmin?bookISBN=${book.getBookISBN()}" style="margin-left:12%;">书籍评价总览</a>
        <br><br>
        <a href="${pageContext.request.contextPath}/purchase/showPurchaseByBook?bookISBN=${book.getBookISBN()}" style="margin-left:12%;">书籍购买总览</a>
        <input type="file" name="photo" title="点击上传图片" style="margin-left: 22%;margin-top: 5%">
    </form>


    <div align="center">
        <input type="button" value="提交" onclick="upload()" class="ui primary button"/>
        <input type="button" value="返回" onclick="Return()" class="ui toggle button" style="margin-left: 7%;margin-top: 7%"/>
    </div>


    <script src="${pageContext.request.contextPath}/statics/js/jquery-3.6.0.js"></script>
    <script>
        function upload(){
            var item = new FormData(document.getElementById("item"));
            $.post({
                url:"${pageContext.request.contextPath}/book/updateBook",
                data:item,
                processData:false,
                contentType:false,
            });
            sleep(1000).then(() => {
                alert("修改成功！");
                window.location = "${pageContext.request.contextPath}/book/findAllBooksAdmin";
            })
        }

        //改良setTimeout()函数
        function sleep (time) {
            return new Promise((resolve) => setTimeout(resolve, time));
        }

        function Return(){
            window.location = "${pageContext.request.contextPath}/book/findAllBooksAdmin";
        }
    </script>

</div>
